<%--
  Created by IntelliJ IDEA.
  User: xiaoji
  Date: 2014/12/15
  Time: 15:17
  To change this template use File | Settings | File Templates.
--%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set value="${pageContext.request.contextPath}" var="path" scope="page"/>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f" %>
<%@ taglib prefix="spring" uri="/WEB-INF/lib/spring.tld"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<html>
<head>
    <title><spring:message code='usercenter.index.title' /></title>
    <link href="${path}/style/acg/css/style.css" rel="stylesheet" type="text/css" />
    <script src="${path}/js/jquery.min.js" type="text/javascript"></script>
    <script src="${path}/plugins/validate/jquery.validate.min.js" type="text/javascript"></script>
    <link href="${path}/plugins/page/kkpager.css" rel="stylesheet">
    <script src="${path}/plugins/page/kkpager.js" type="text/javascript"></script>
</head>
<body>
<jsp:include page="../public/header.jsp">
    <jsp:param    name="usercenter"    value="true"    />
</jsp:include>
<jsp:include page="../usercenter/leftMenu.jsp"></jsp:include>

<div class="member_box">
    <div class="member_title">
        <ul>
            <li><a href="${path}/usercenter/getUserInfo.html" ><spring:message code='usercenter.withdrawal.msg1' /></a></li>
            <li><a href="${path}/usercenter/topup.html"><spring:message code='usercenter.withdrawal.msg2' /></a></li>
            <li class="hover"><a href="javascript:void(0);"><spring:message code='usercenter.withdrawal.msg3' /></a></li>
        </ul>
    </div>
    <div class="member_account">
        <div class="member_form">
            <ul>
                <li class="clearfix">
                    <dl class="clearfix">
                        <dt><spring:message code='usercenter.withdrawal.msg4' /></dt>
                        <dd><input type="text" id="payOutPrice" name="payOutPrice" class="txtorg" /><input type="button" id="payout2"  value="<spring:message code='usercenter.withdrawal.msg5' />" class="btngorg" /></dd>
                    </dl>
                </li>
                <li class="clearfix">
                    <dl class="clearfix">
                        <dt>&nbsp;</dt>
                        <dd><spring:message code='usercenter.withdrawal.msg6' /><em class="color_red">￥<f:formatNumber value="${sessionScope.curUser.freezeMoney}" pattern="#,#00.00#"/></em><spring:message code='usercenter.withdrawal.msg7' />,
                            <spring:message code='usercenter.withdrawal.msg19' /><em class="color_red">￥<f:formatNumber value="${sessionScope.curUser.wallet-sessionScope.curUser.freezeMoney}" pattern="#,#00.00#"/></em></dd>
                    </dl>
                </li>
            </ul>
        </div>
        <div class="member_account_listbox">
            <div class="member_title"><spring:message code='usercenter.withdrawal.msg8' /></div>
            <div class="member_account_list">
                <ul id="pagelist">

                </ul>

                <div  id="kkpager" style="text-align: center">
                </div>
            </div>
        </div>
    </div>
</div>
<form id="frm1">
    <div id="openwin1" class="openwin" style="width: 1382px; height: 600px;display: none">
        <div id="openbox1" class="openbox" style="margin-top: 108.5px;">
            <h1><spring:message code='usercenter.withdrawal.msg14' /><span id="closeopen1" class="closeopen" onclick="closeWin(1)">×</span></h1>
            <div class="openmain">
                <ul>
                    <li class="clearfix">
                        <dl class="clearfix">
                            <dt><spring:message code='usercenter.withdrawal.msg15' />：</dt>
                            <dd style="width: 500px">
                                ${sessionScope.curUser.realName}
                            </dd>
                        </dl>
                    </li>
                    <li class="clearfix">
                        <dl class="clearfix">
                            <dt><spring:message code='usercenter.withdrawal.msg16' />：</dt>
                            <dd style="width: 500px">
                                ${sessionScope.curUser.alipay}
                            </dd>
                        </dl>
                    </li>
                    <li class="clearfix">
                        <dl class="clearfix">
                            <dt><spring:message code='usercenter.withdrawal.msg17' />：</dt>
                            <dd style="width: 500px" id="applyMoney">

                            </dd>
                        </dl>
                    </li>
                    <li class="clearfix">
                        <dl class="clearfix">
                            <dt>&nbsp;</dt>
                            <dd>
                                <input type="submit" value="<spring:message code='usercenter.withdrawal.msg18' />" class="btnsubmit">
                            </dd>
                        </dl>
                    </li>

                </ul>
            </div>
        </div>
    </div>
</form>

<script>
    var pageSize = 10;
    function initBeanInfo(page, rows) {
        //异步获取生产计划
        pageSize = rows;
        $.post("${path}/usercenter/withdrawalList.html", {
            page: page,
            rows: rows
        }, function (data) {
            var list = data.pageInfo.list;
            var htmlstr = "";
            if (list != null) {
                htmlstr += ' <li class="clearfix">' +
                        ' <p class="a_time"><spring:message code='usercenter.withdrawal.msg20' /></p>' +
                        '<p class="a_remark"><spring:message code='usercenter.withdrawal.msg21' /></p>' +
                        '<p class="a_state"><spring:message code='usercenter.withdrawal.msg22' /></p>' +
                        '</li>';
                for (var i = 0; i < list.length; i++) {
                    var obj = list[i];
                    obj.walletStatus = obj.walletStatus == 131101 ? "<spring:message code='usercenter.withdrawal.msg9' />" : "<spring:message code='usercenter.withdrawal.msg10' />";
                    htmlstr += ' <li class="clearfix">' +
                            ' <p class="a_time">' + obj.time + '</p>' +
                            '<p class="a_remark"><spring:message code='usercenter.withdrawal.msg3' />' + obj.money + '<spring:message code='usercenter.withdrawal.msg11' /></p>' +
                            '<p class="a_state">' + obj.withdrawStatus + '</p>' +
                            '</li>';
                }
                $("#pagelist").html(htmlstr);
                var pager = data.pageInfo;
                //分页
                createPage(pager.pageNum, pager.pages, pager.total, data.type);
            }
            },"json");
    }
        //分页方法
        //currentPage 当前页
        //rows 每页条数
        //total 总数
        function createPage(currentPage, totalPage, totalCount,type) {
            var totalPage = totalPage;
            var totalRecords = totalCount;
            var pageNo = currentPage;
            if (!pageNo) {
                pageNo = 1;
            }
            //生成分页
            //有些参数是可选的，比如lang，若不传有默认值
            kkpager.generPageHtml({
                pno: pageNo,
                //总页码
                total: totalPage,
                //总数据条数
                totalRecords: totalRecords,
                //链接前部
                hrefFormer: 'index',
                //链接尾部
                hrefLatter: '',
                //是否显示总页数
                isShowTotalPage: true,
                //是否显示总记录数
                isShowTotalRecords: true,
                //是否显示页码跳转输入框
                isGoPage: true,
                //getLink: function (n) {
                //    return this.hrefFormer + this.hrefLatter + "?pno=" + n;
                //}
                //,
                mode : 'click',//默认值是link，可选link或者click
                click : function(n){
                    //this.selectpage(n);
                    initBeanInfo(n, pageSize,type);
                    return false;
                },
                lang				: {
                    firstPageText			: '<spring:message code="firstPageText"/>',
                    firstPageTipText		: '<spring:message code="firstPageTipText"/>',
                    lastPageText			: '<spring:message code="lastPageText"/>',
                    lastPageTipText			: '<spring:message code="lastPageTipText"/>',
                    prePageText				: '<spring:message code="prePageText"/>',
                    prePageTipText			: '<spring:message code="prePageTipText"/>',
                    nextPageText			: '<spring:message code="nextPageText"/>',
                    nextPageTipText			: '<spring:message code="nextPageTipText"/>',
                    totalPageBeforeText		: '<spring:message code="totalPageBeforeText"/>',
                    totalPageAfterText		: '<spring:message code="totalPageAfterText"/>',
                    totalRecordsAfterText	: '<spring:message code="totalRecordsAfterText"/>',
                    gopageBeforeText		: '<spring:message code="gopageBeforeText"/>',
                    gopageButtonOkText		: '<spring:message code="gopageButtonOkText"/>',
                    gopageAfterText			: '<spring:message code="gopageAfterText"/>',
                    buttonTipBeforeText		: '<spring:message code="buttonTipBeforeText"/>',
                    buttonTipAfterText		: '<spring:message code="buttonTipAfterText"/>'
                }
            },true);
        }
        $(function(){
            initBeanInfo(1,10);
            $("#payout2").click(function(){
                var payOutPrice = $("#payOutPrice").val();
                if(!isNaN(payOutPrice)){
                    //alert("<spring:message code='usercenter.withdrawal.msg12' />"+payOutPrice);
                    $("#applyMoney").html("￥"+payOutPrice);
                    openWin(1);
                }else{
                    alert("<spring:message code='usercenter.withdrawal.msg13' />");
                }
            });
        });

    //支付申请提交
    var validate1 = $("#frm1").validate({
        rules : {
        },
        messages : {
        },
        success: function(label) {//验证成功添加样式
            label.html("&nbsp;").removeClass("checked").addClass("checked");
        },
        submitHandler : function(){
            var alipay = '${sessionScope.curUser.alipay}';
            var realName = '${sessionScope.curUser.realName}';
            if(alipay == null || alipay==''){
                alert("支付宝不能为空！");
                return ;
            }
            if(realName == null || realName==''){
                alert("真实姓名不能为空！");
                return ;
            }
            $.post("${path}/usercenter/withdrawalApplay.html",{
                payOutPrice:$("#payOutPrice").val()
            },function(data){
                console.log(data);
                if(data.errormsg == undefined){
                    alert("<spring:message code='usercenter.withdrawal.msg9' />");
                    window.location = '${path}/usercenter/withdrawal.html';
                }else{
                    alert("<spring:message code='usercenter.withdrawal.msg10' />");
                }
            },"json");
        }
    });
    var type=1;
    $(window).resize(function() {
        UpdateSize(type);
    });
    function closeWin(type){
        $("#openwin"+type).hide();
    }
    function openWin(type){
        $("#openwin"+type).show();
        type = type;
        UpdateSize(type);
    }
    function UpdateSize(type){
        var _width= parseFloat($(document).width());
        var _height=parseFloat($(window).height());
        if(_width<900){ _width=900;}
        if(_height<600){ _height=600;}
        var open_height=parseFloat($("#openbox"+type).height());
        if(_height<open_height){_height=open_height;}
        var open_mt=(_height-open_height)/2;

        $("#openbox"+type).css({"margin-top":open_mt+"px"});
        $("#openwin"+type).css({"width":_width+"px","height":_height+"px"});
    }
</script>
<jsp:include page="../usercenter/leftMenuEnd.jsp"></jsp:include>
<jsp:include page="../public/footer.jsp"></jsp:include>
</body>
</html>